package data;

import java.util.Hashtable;
import java.util.Set;
import java.util.TreeSet;

import exceptions.ObjectAlreadyInitializedException;

public abstract class SystemData {
	static SystemData _systemData;
	
	
	public static SystemData getInstance(){
		if (_systemData==null)
			return new SystemXmlDataBase();
		else return _systemData;
	}
	public static void doXML() {
		xml.DataManipulate.readFromFile();
	}
	public static void doSQL() throws Exception{
		SQLinit();
	}

	public static SystemData XMLinit(Hashtable<String,MovieTuple> movies, Hashtable<String,UserTuple> users, Hashtable<String, RatingTuple> ratings) throws Exception {
		if (_systemData==null) {
			_systemData= new SystemXmlDataBase(movies,users,ratings);
			return _systemData;
		}
		else throw new ObjectAlreadyInitializedException();//to do make a smart exception
	}
	
	public static SystemData SQLinit() throws Exception {
		if (_systemData==null) {
			_systemData= new SystemSqlDatabase();
			return _systemData;
		}
		else throw new ObjectAlreadyInitializedException();//to do make a smart exception
	}
	
	public abstract RatingTuple getRating(String user, String movie);
	
	/**
	 *
	 * @return the movie
	 */
	public abstract MovieTuple getMovie(String movie);

	/**
	 *
	 * @return the user
	 */
	public abstract UserTuple getUser(String user);

	//RatingTuple getRec(String rec);

	//boolean equals(SystemData other);

	@Deprecated
	public abstract	RatingTuple getRandomRec();

	public abstract void addMovie(MovieTuple movie);

	public abstract void addRating(String user, String movie, String rating, String description);

	public abstract void addUser(UserTuple user);

	public abstract void deleteUser(UserTuple user);

	public abstract void deleteMovie(MovieTuple movie);

	public abstract void deleteRating(String movieName, String userName);

	public abstract void editRating(String user, String movie, String description, String rate,	String date);

	public abstract void editUser(String name, String bdate, boolean b);

	public abstract void changeUserPassword(String name, String password);

	public abstract UserTuple createUser(String name, String pw, String sex, String bdate, String type);

	public abstract TreeSet<RatingTuple> getRatingsByUser(String name);

	public abstract TreeSet<RatingTuple> getRatingsByMovie(String movie);
	
	public abstract Set<MovieTuple> getAllMovies();
	
	public abstract Set<UserTuple> getAllUsers();

	public abstract Set<RatingTuple> getAllRatings();
	
	public abstract void exit();

	public abstract String[] getMovieNames();

	public abstract String[] getUserNames(String username);
	
	public abstract String[] search(String str);
	
	public abstract double getAvg(String user);

}